<#-- sql文件生成模板 -->
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${namespace}">
	
	<resultMap id="BaseResultMap" type="${basePackage}${r"."}entity${r"."}${entityName}">
	<#list mapperRelations as mapperRelation>
	<#if primaryKey ==mapperRelation.column>
		<id column="${mapperRelation.column}" property="${mapperRelation.property}"/>
	<#else>
		<result column="${mapperRelation.column}" property="${mapperRelation.property}"/> 
	</#if>
	</#list>
	</resultMap>
	
	<#list selectComponents as selectComponent>
	<select id="${selectComponent.id}" resultMap="BaseResultMap" parameterType="${selectComponent.parameterType}">
		select 
		<#list mapperRelations as mapperRelation>
			${mapperRelation.column}<#if mapperRelation_has_next>,</#if>
		</#list>
    	from ${tableName}
    	where 1=1
    	<#list selectComponent.conditions as contiditon>
			and ${contiditon.column} =${r"#"}{${contiditon.property}}
		</#list>
	</select>
	</#list>
	
	<update id="${updateComponents.id}" parameterType="${updateComponents.parameterType}">
		update ${tableName} 
		<trim prefix="set" suffixOverrides=","> 
		<#list mapperRelations as mapperRelation>
			<if test="${mapperRelation.property} !=null and ${mapperRelation.property} !='' ">
				${mapperRelation.column} = ${r"#"}{${mapperRelation.property}},
			</if>
		</#list>
		</trim>
		where ${primaryKey} = ${r"#"}{${primaryName}}
	</update>
	
	<insert id="${addComponents.id}" parameterType="${addComponents.parameterType}" > 
		insert into ${tableName} (
		<#list mapperRelations as mapperRelation>
			${mapperRelation.column}<#if mapperRelation_has_next>,</#if>
		</#list>
		)values(
		<#list mapperRelations as mapperRelation>
			${r"#"}{ ${mapperRelation.property} }<#if mapperRelation_has_next>,</#if>
		</#list>	
		)
	</insert>
</mapper>